package sort;

/**
 * Created by Stay on 2017/5/7  21:47.
 */
public class SortUtils {


    public static void main(String[] args) {
        int[] array = {3, 5, 2, 7, 12, 43, 23, 41};
        choiceSort(array);
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    }

    /**
     * 冒泡排序
     * 时间复杂度 O(n2)
     *
     *
     * @param array
     */
    public static void bubbleSort(int[] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = i; j < array.length - 1; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
    }

    /**
     * 简单选择排序
     *
     * @param array
     */
    public static void choiceSort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            int min = array[i];
            for(int j = i + 1; j < array.length; j++){
                if(array[j] < min){
                    int temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                    min = array[i];
                }
            }
        }
    }

    /**
     * 插入排序
     *
     * @param array
     */
    public static void insertSort(int[] array){
        for(int i = 0; i < array.length; i++){
            if(array[i] < array[i+1]){

            }
        }
    }



    private SortUtils() {
    }
}
